#include <maths/Vector2.h>
#include <math.h>
namespace fort
{
	//-- Compare two vectors
	bool Vector2::Equals(Vector2 vec)
	{
		return (x == vec.x && y == vec.y);
	}


	//-- returns distance given two vectors
	double Vector2::Distance(Vector2 a, Vector2 b)
	{
		float distX = b.x - a.x;
		float distY = b.y - a.y;
		return sqrt(distX*distX + distY*distY);
	}

	//-- Returns length
	float Vector2::Length()
	{
		return (float)sqrt((x*x) + (y*y));
	}

	//-- Sets the values of the vector
	void Vector2::Set(float px, float py)
	{
		x = px;
		y = py;
	}

	//-- Normalise the vector
	void Vector2::Normalise()
	{
		//-- sets length to 1
		double length = sqrt(x*x + y*y);

		if (length != 0.0) {
			float s = 1.0f / (float)length;
			x = x*s;
			y = y*s;
		}
	}

	//-- Scales a Vector2 by the given scalar
	void Vector2::Scale(double scalar)
	{
		x *= scalar;
		y *= scalar;
	}

	//-- subtracts the given vector
	void Vector2::Subtract(Vector2 v)
	{
		x -= v.x;
		y -= v.y;
	}


}